import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/page/common/common_loading_dialog.dart';
import 'package:flutter_learn_vi/src/page/mine/password/update_passwrod_controller.dart';
import 'package:flutter_learn_vi/src/utils/string_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';
import 'package:get/get.dart';

import '../../login/kuangdeng/kuang_input_widget.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/4.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单

class UpdatePasswordPage extends StatelessWidget {
  //焦点控制器
  FocusNode _userNameFocusNode = new FocusNode();
  FocusNode _passwordFocusNode = new FocusNode();
  FocusNode _passwordFocusNode2 = new FocusNode();

  //文本输入框控制器
  TextEditingController _userNameController = TextEditingController();
  TextEditingController _passwordController = TextEditingController();
  TextEditingController _passwordController2 = TextEditingController();

  @override
  Widget build(BuildContext context) {
    Get.put(UpdateassowrdController());
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("修改密码"),
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        padding: EdgeInsets.all(20),
        child: Column(
          children: [
            Container(
              height: 54,
              alignment: Alignment.center,
              padding: EdgeInsets.only(left: 40, right: 40),
              child: KuangDengInputWidget(
                labelText: "原密码",
                hintText: '请输入原密码',
                focusNode: _userNameFocusNode,
                controller: _userNameController,
                obscureText: false,
                prefixIconData: Icons.mail_outline,
                submit: (String value) {
                  //焦点切换
                  _userNameFocusNode.unfocus();
                  FocusScope.of(context).requestFocus(_passwordFocusNode);
                },
              ),
            ),
            SizedBox(
              height: 24,
            ),
            Container(
              height: 54,
              alignment: Alignment.center,
              padding: EdgeInsets.only(left: 40, right: 40),
              child: KuangDengInputWidget(
                labelText: "新密码",
                hintText: '请输入新密码',
                focusNode: _passwordFocusNode,
                controller: _passwordController,
                obscureText: false,
                prefixIconData: Icons.mail_outline,
                submit: (String value) {
                  //焦点切换
                  _passwordFocusNode.unfocus();
                  FocusScope.of(context).requestFocus(_passwordFocusNode2);
                },
              ),
            ),
            SizedBox(
              height: 24,
            ),
            Container(
              height: 54,
              alignment: Alignment.center,
              padding: EdgeInsets.only(left: 40, right: 40),
              child: KuangDengInputWidget(
                labelText: "确认新密码",
                hintText: '请确认新密码',
                focusNode: _passwordFocusNode2,
                controller: _passwordController2,
                obscureText: false,
                prefixIconData: Icons.mail_outline,
                submit: (String value) {
                  //焦点切换
                  _passwordFocusNode2.unfocus();
                },
              ),
            ),
            SizedBox(
              height: 24,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                GetBuilder(
                  builder: (UpdateassowrdController controller) {
                    if (controller.isSubmit) {
                      return LoadingWidget();
                    }
                    return ElevatedButton(
                        onPressed: () {
                          String userName = _userNameController.text;
                          String password = _passwordController.text;
                          String password2 = _passwordController2.text;
                          if (StringUtils.isEmpty(userName)) {
                            ToastUtils.showToast('请输入原密码');
                            return;
                          }
                          if (StringUtils.isEmpty(password)) {
                            ToastUtils.showToast('请输入新密码');
                            return;
                          }
                          if (StringUtils.isEmpty(password2)) {
                            ToastUtils.showToast('请再次确认密码');
                            return;
                          }
                          if (password != password2) {
                            ToastUtils.showToast('两次输入的密码不一至 请核对');
                            return;
                          }
                          Get.find<UpdateassowrdController>()
                              .submitAlertUserPassword(userName, password);
                        },
                        child: Text("确认"));
                  },
                ),
                SizedBox(
                  width: 40,
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}
